package org.example.map.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.example.commons.entity.Comment;
import com.example.commons.entity.Map;
import jakarta.annotation.Resource;
import org.example.map.mapper.MapMapper;
import org.example.map.service.CommentService;
import org.example.map.service.MapService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @program: authority-v3.0.7
 * @ClassName:MapServiceImpl
 * @description: 地图列表 service实现类
 * @author:dyy
 * @Version 3.0
 **/

@Service
public class MapServiceImpl extends ServiceImpl<MapMapper, Map> implements MapService {
    @Resource
    private CommentService commentService;

    @Override
    @Transactional
    public boolean removeMapWithComments(Long id) {
        // 删除关联评论
        commentService.remove(new LambdaQueryWrapper<Comment>().eq(Comment::getAid, id));
        // 删除地图
        return this.removeById(id);
    }

    @Override
    @Transactional
    public boolean removeMapsWithComments(List<Long> ids) {
        // 删除所有关联评论
        commentService.remove(new LambdaQueryWrapper<Comment>().in(Comment::getAid, ids));
        // 删除地图
        return this.removeByIds(ids);
    }
}
